
package com.sunwayhorizo.health.hl7.datatypes.common.gtsparser;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_INT;
import com.sunwayhorizo.health.hl7.datatypes.OID;
import com.sunwayhorizo.health.hl7.datatypes.common.INTImpl;
import com.sunwayhorizo.health.hl7.datatypes.common.LIST_INTAdapterImpl;
import com.sunwayhorizo.health.hl7.datatypes.common.OIDImpl;

import java.io.InputStream;
import java.io.Reader;

import java.util.Enumeration;
import java.util.LinkedList;
import java.util.Vector;


public class OIDParser implements OIDParserConstants
 {
     public static final String RCS_ID
         = "$Header: OIDParser.java 115.0 2005/09/16 10:39:36 mmoores noship $";
     public static final boolean RCS_ID_RECORDED
         = (VersionInfo.recordClassVersion
            ("$Header: OIDParser.java 115.0 2005/09/16 10:39:36 mmoores noship $",
             "oracle.apps.ctb.hl7.types.common.gtsparser"));
     public OIDParserTokenManager token_source;
     SimpleCharStream jj_input_stream;
     public Token token;
     public Token jj_nt;
     private int jj_ntk;
     private Token jj_scanpos;
     private Token jj_lastpos;
     private int jj_la;
     public boolean lookingAhead = false;
     private boolean jj_semLA;
     private int jj_gen;
     private final int[] jj_la1;
     private static int[] jj_la1_0;
     private final JJCalls[] jj_2_rtns;
     private boolean jj_rescan;
     private int jj_gc;
     private final LookaheadSuccess jj_ls;
     private Vector jj_expentries;
     private int[] jj_expentry;
     private int jj_kind;
     private int[] jj_lasttokens;
     private int jj_endpos;
     
     private static final class LookaheadSuccess extends Error
     {
     }
     
     static final class JJCalls
     {
         int gen;
         Token first;
         int arg;
         JJCalls next;
     }
     
     public final OID oid(String string) throws ParseException {
         if (jj_2_1(2)) {
             INT var_int = integer();
             jj_consume_token(2);
             LinkedList linkedlist = tail();
             linkedlist.addFirst(var_int);
             INT var_int_0_ = (INT) linkedlist.removeLast();
             INT[] var_ints = new INT[linkedlist.size()];
             linkedlist.toArray(var_ints);
             LIST_INT list_int = LIST_INTAdapterImpl.valueOf(var_ints);
             return new OIDImpl(var_int_0_, list_int, string);
         }
         switch (jj_ntk == -1 ? jj_ntk() : jj_ntk) {
         case 1: {
             INT var_int = integer();
             return new OIDImpl(var_int, LIST_INTAdapterImpl.nullLIST_INT(null),
                                string);
         }
         default:
             jj_la1[0] = jj_gen;
             jj_consume_token(-1);
             throw new ParseException();
         }
     }
     
     public final LinkedList tail() throws ParseException {
         if (jj_2_2(2)) {
             INT var_int = integer();
             jj_consume_token(2);
             LinkedList linkedlist = tail();
             linkedlist.addFirst(var_int);
             return linkedlist;
         }
         switch (jj_ntk == -1 ? jj_ntk() : jj_ntk) {
         case 1: {
             INT var_int = integer();
             LinkedList linkedlist = new LinkedList();
             linkedlist.add(var_int);
             return linkedlist;
         }
         default:
             jj_la1[1] = jj_gen;
             jj_consume_token(-1);
             throw new ParseException();
         }
     }
     
     public final INT integer() throws ParseException {
         Token token = jj_consume_token(1);
         Long var_long = Long.valueOf(token.image);
         return INTImpl.valueOf(var_long.longValue());
     }
     
     private final boolean jj_2_1(int i) {
         jj_la = i;
         jj_lastpos = jj_scanpos = token;
         try {
             return !jj_3_1();
         } catch (LookaheadSuccess lookaheadsuccess) {
             return true;
         } finally {
             jj_save(0, i);
         }
     }
     
     private final boolean jj_2_2(int i) {
         jj_la = i;
         jj_lastpos = jj_scanpos = token;
         try {
             return !jj_3_2();
         } catch (LookaheadSuccess lookaheadsuccess) {
             return true;
         } finally {
             jj_save(1, i);
         }
     }
     
     private final boolean jj_3_2() {
         if (jj_3R_1())
             return true;
         if (jj_scan_token(2))
             return true;
         return false;
     }
     
     private final boolean jj_3R_1() {
         if (jj_scan_token(1))
             return true;
         return false;
     }
     
     private final boolean jj_3_1() {
         if (jj_3R_1())
             return true;
         if (jj_scan_token(2))
             return true;
         return false;
     }
     
     private static void jj_la1_0() {
         jj_la1_0 = new int[] { 2, 2 };
     }
     
     public OIDParser(InputStream inputstream) {
         jj_la1 = new int[2];
         jj_2_rtns = new JJCalls[2];
         jj_rescan = false;
         jj_ls = new LookaheadSuccess();
         jj_expentries = new Vector();
         jj_kind = -1;
         jj_lasttokens = new int[100];
         jj_input_stream = new SimpleCharStream(inputstream, 1, 1);
         token_source = new OIDParserTokenManager(jj_input_stream);
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     public void ReInit(InputStream inputstream) {
         jj_input_stream.ReInit(inputstream, 1, 1);
         token_source.ReInit(jj_input_stream);
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     public OIDParser(Reader reader) {
         jj_la1 = new int[2];
         jj_2_rtns = new JJCalls[2];
         jj_rescan = false;
         jj_ls = new LookaheadSuccess();
         jj_expentries = new Vector();
         jj_kind = -1;
         jj_lasttokens = new int[100];
         jj_input_stream = new SimpleCharStream(reader, 1, 1);
         token_source = new OIDParserTokenManager(jj_input_stream);
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     public void ReInit(Reader reader) {
         jj_input_stream.ReInit(reader, 1, 1);
         token_source.ReInit(jj_input_stream);
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     public OIDParser(OIDParserTokenManager oidparsertokenmanager) {
         jj_la1 = new int[2];
         jj_2_rtns = new JJCalls[2];
         jj_rescan = false;
         jj_ls = new LookaheadSuccess();
         jj_expentries = new Vector();
         jj_kind = -1;
         jj_lasttokens = new int[100];
         token_source = oidparsertokenmanager;
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     public void ReInit(OIDParserTokenManager oidparsertokenmanager) {
         token_source = oidparsertokenmanager;
         token = new Token();
         jj_ntk = -1;
         jj_gen = 0;
         for (int i = 0; i < 2; i++)
             jj_la1[i] = -1;
         for (int i = 0; i < jj_2_rtns.length; i++)
             jj_2_rtns[i] = new JJCalls();
     }
     
     private final Token jj_consume_token(int i) throws ParseException {
         Token token;
         if ((token = this.token).next != null)
             this.token = this.token.next;
         else
             this.token = this.token.next = token_source.getNextToken();
         jj_ntk = -1;
         if (this.token.kind == i) {
             jj_gen++;
             if (++jj_gc > 100) {
                 jj_gc = 0;
                 for (int i_1_ = 0; i_1_ < jj_2_rtns.length; i_1_++) {
                     for (JJCalls jjcalls = jj_2_rtns[i_1_]; jjcalls != null;
                          jjcalls = jjcalls.next) {
                         if (jjcalls.gen < jj_gen)
                             jjcalls.first = null;
                     }
                 }
             }
             return this.token;
         }
         this.token = token;
         jj_kind = i;
         throw generateParseException();
     }
     
     private final boolean jj_scan_token(int i) {
         if (jj_scanpos == jj_lastpos) {
             jj_la--;
             if (jj_scanpos.next == null)
                 jj_lastpos = jj_scanpos = jj_scanpos.next
                     = token_source.getNextToken();
             else
                 jj_lastpos = jj_scanpos = jj_scanpos.next;
         } else
             jj_scanpos = jj_scanpos.next;
         if (jj_rescan) {
             int i_2_ = 0;
             Token token;
             for (token = this.token; token != null && token != jj_scanpos;
                  token = token.next)
                 i_2_++;
             if (token != null)
                 jj_add_error_token(i, i_2_);
         }
         if (jj_scanpos.kind != i)
             return true;
         if (jj_la == 0 && jj_scanpos == jj_lastpos)
             throw jj_ls;
         return false;
     }
     
     public final Token getNextToken() {
         if (token.next != null)
             token = token.next;
         else
             token = token.next = token_source.getNextToken();
         jj_ntk = -1;
         jj_gen++;
         return token;
     }
     
     public final Token getToken(int i) {
         Token token = lookingAhead ? jj_scanpos : this.token;
         for (int i_3_ = 0; i_3_ < i; i_3_++) {
             if (token.next != null)
                 token = token.next;
             else
                 token = token.next = token_source.getNextToken();
         }
         return token;
     }
     
     private final int jj_ntk() {
         if ((jj_nt = token.next) == null)
             return jj_ntk = (token.next = token_source.getNextToken()).kind;
         return jj_ntk = jj_nt.kind;
     }
     
     private void jj_add_error_token(int i, int i_4_) {
         if (i_4_ < 100) {
             if (i_4_ == jj_endpos + 1)
                 jj_lasttokens[jj_endpos++] = i;
             else if (jj_endpos != 0) {
                 jj_expentry = new int[jj_endpos];
                 for (int i_5_ = 0; i_5_ < jj_endpos; i_5_++)
                     jj_expentry[i_5_] = jj_lasttokens[i_5_];
                 boolean bool = false;
                 Enumeration enumeration = jj_expentries.elements();
                 while (enumeration.hasMoreElements()) {
                     int[] is = (int[]) enumeration.nextElement();
                     if (is.length == jj_expentry.length) {
                         bool = true;
                         for (int i_6_ = 0; i_6_ < jj_expentry.length; i_6_++) {
                             if (is[i_6_] != jj_expentry[i_6_]) {
                                 bool = false;
                                 break;
                             }
                         }
                         if (bool)
                             break;
                     }
                 }
                 if (!bool)
                     jj_expentries.addElement(jj_expentry);
                 if (i_4_ != 0)
                     jj_lasttokens[(jj_endpos = i_4_) - 1] = i;
             }
         }
     }
     
     public ParseException generateParseException() {
         jj_expentries.removeAllElements();
         boolean[] bools = new boolean[3];
         for (int i = 0; i < 3; i++)
             bools[i] = false;
         if (jj_kind >= 0) {
             bools[jj_kind] = true;
             jj_kind = -1;
         }
         for (int i = 0; i < 2; i++) {
             if (jj_la1[i] == jj_gen) {
                 for (int i_7_ = 0; i_7_ < 32; i_7_++) {
                     if ((jj_la1_0[i] & 1 << i_7_) != 0)
                         bools[i_7_] = true;
                 }
             }
         }
         for (int i = 0; i < 3; i++) {
             if (bools[i]) {
                 jj_expentry = new int[1];
                 jj_expentry[0] = i;
                 jj_expentries.addElement(jj_expentry);
             }
         }
         jj_endpos = 0;
         jj_rescan_token();
         jj_add_error_token(0, 0);
         int[][] is = new int[jj_expentries.size()][];
         for (int i = 0; i < jj_expentries.size(); i++)
             is[i] = (int[]) jj_expentries.elementAt(i);
         return new ParseException(token, is, OIDParserConstants.tokenImage);
     }
     
     public final void enable_tracing() {
         /* empty */
     }
     
     public final void disable_tracing() {
         /* empty */
     }
     
     private final void jj_rescan_token() {
         jj_rescan = true;
         int i = 0;
         while (i < 2) {
             JJCalls jjcalls = jj_2_rtns[i];
             for (;;) {
                 if (jjcalls.gen > jj_gen) {
                     jj_la = jjcalls.arg;
                     jj_lastpos = jj_scanpos = jjcalls.first;
                     switch (i) {
                     case 0:
                         jj_3_1();
                         break;
                     case 1:
                         jj_3_2();
                         break;
                     }
                 }
                 jjcalls = jjcalls.next;
                 if (jjcalls == null) {
                     i++;
                     break;
                 }
             }
         }
         jj_rescan = false;
     }
     
     private final void jj_save(int i, int i_8_) {
         JJCalls jjcalls;
         for (jjcalls = jj_2_rtns[i]; jjcalls.gen > jj_gen;
              jjcalls = jjcalls.next) {
             if (jjcalls.next == null) {
                 jjcalls = jjcalls.next = new JJCalls();
                 break;
             }
         }
         jjcalls.gen = jj_gen + i_8_ - jj_la;
         jjcalls.first = token;
         jjcalls.arg = i_8_;
     }
     
     static {
         jj_la1_0();
     }
 }